package com.bos.mapper;

import org.apache.ibatis.jdbc.SQL;

public class SalesProvider {
    //这是用来操作销售表多条件的类
    public String findSales(final String[] sleader, final String[] status) {
        String sql = new SQL() {
            {
                // 什么也不输入的话查询出所有的数据
                SELECT("*");
                FROM("sales");
                WHERE("1=1");
                //如果负责人选中了的话
                if (null != sleader && 0 < sleader.length) {
                    String str = "";
                    if (sleader.length == 1) {
                        str = "('" + sleader[0] + "')";
                    } else {
                        for (int i = 0; i < sleader.length - 1; i++) {
                            if (0 == i) {
                                str = "('" + sleader[0] + "',";
                            } else {
                                str += "'" + sleader[i] + "',";
                            }
                        }
                        str += "'" + sleader[sleader.length - 1] + "')";
                    }

                    AND().WHERE("sleader in " + str);
                }
                if (null != status && 0 < status.length) {
                    String strs = "";
                    if (status.length == 1) {
                        strs = "('" + status[0] + "')";
                    } else {
                        for (int i = 0; i < status.length - 1; i++) {
                            if (0 == i) {
                                strs = "('" + sleader[0] + "',";
                            } else {
                                strs += "'" + sleader[i] + "',";
                            }
                        }
                        strs += "'" + sleader[sleader.length - 1] + "')";
                    }
                    AND().WHERE("status in " + strs);
                }
            }
        }.toString();
        return sql;
    }


}
